const fs = require('fs');

function Loader() {
    // 读取样式文件内容
    const context = fs.readFileSync(this.resource, 'utf-8');

    // 构造创建style节点的立即执行函数
    const iife = `(() => {
        const styleNode = document.createElement('style');
        styleNode.type = 'text/css';
        styleNode.innerHTML = ${JSON.stringify(context)};
        document.body.appendChild(styleNode);
    })()`;
    
    // 导出javascript对象
    return `export default ${iife}`;
}

module.exports = Loader;